#! /usr/bin/env python

import sys

LINES = 48
COLS = 64

def int2bin(n):
    bstr = ""
    while n > 0:
        bstr = str(n % 2) + bstr
        n = n / 2
    return bstr.zfill(8)

f = open(sys.argv[1], "r")
entrada = f.read()
entrada = entrada.split("\n\n")

for e in xrange(len(entrada)):
    print """when "%s" => """ % int2bin(e)
    a = [i.strip() for i in entrada[e].split("\n")]
    title = a[0]
    a = a[1:]
    for l in xrange(len(a)):
        cols_faltando = COLS - len(a[l])
        for i in xrange(cols_faltando / 2):
            a[l] += "."
        for i in xrange(cols_faltando / 2 + cols_faltando % 2):
            a[l] = "." + a[l] 
    linhas_faltando = LINES - len(a)
    for i in xrange(linhas_faltando / 2):
        a.append("." * COLS )
    for i in xrange(linhas_faltando / 2 + linhas_faltando % 2):
        a.insert(0, "." * COLS )

    print title
    
    for i in xrange(LINES):
        for j in xrange(COLS):
            if a[i][j] in ['1', '*']:
                print "gameA(%d)(%d) <= '1';" % (j,i)

